package com.rd.config;

import com.rd.common.CommonResult;
import com.rd.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public CommonResult handleException(Exception exception){
        log.info("你Controller出现了异常,{}",exception.getMessage());
        //在控制台上打印错误信息
        exception.printStackTrace();
        return ResultUtil.buildError(exception.getMessage());
    }
}
